﻿Imports System
Imports System.Workflow.ComponentModel
Imports System.Workflow.ComponentModel.Compiler

Namespace System.Workflow.Activities
    Friend NotInheritable Class EventHandlersValidator
        Inherits CompositeActivityValidator
        ' Methods
        Public Overrides Function Validate(ByVal manager As ValidationManager, ByVal obj As Object) As ValidationErrorCollection
            Dim errors As ValidationErrorCollection = MyBase.Validate(manager, obj)
            Dim activity As EventHandlersActivity = [TryCast](obj,EventHandlersActivity)
            If (activity Is Nothing) Then
                Throw New ArgumentException(SR.GetString("Error_UnexpectedArgumentType", New Object() { GetType(EventHandlersActivity).FullName }), "obj")
            End If
            If (activity.Parent Is Nothing) Then
                errors.Add(New ValidationError(SR.GetString("Error_MustHaveParent"), &H522))
                Return errors
            End If
            If Not TypeOf activity.Parent Is EventHandlingScopeActivity Then
                errors.Add(New ValidationError(SR.GetString("Error_EventHandlersDeclParentNotScope", New Object() { activity.Parent.QualifiedName }), &H522))
            End If
            Dim flag As Boolean = False
            Dim activity2 As Activity
            For Each activity2 In activity.EnabledActivities
                If Not TypeOf activity2 Is EventDrivenActivity Then
                    flag = True
                End If
            Next
            If flag Then
                errors.Add(New ValidationError(SR.GetString("Error_ListenNotAllEventDriven"), &H514))
            End If
            Return errors
        End Function

    End Class
End Namespace

